<?php include "classes.inc" ?>
<?php include "constants.inc" ?>
<?php session_start(); ?>
<?php
	if ( isset($_SESSION['user']) == false || ( isset($_GET['club_id']) == false ||
		($_GET['club_id'] != $_SESSION['user']->club_id) && $_SESSION['user']->club_id != 100) ) {
    	redirect("/clubs/clubs.php");
    }
	$user = $_SESSION['user'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Club detail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../assets/css/default.css" rel="stylesheet" type="text/css">
</head>

<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" class="default">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="7">
                        <img src="/assets/images/spacer.gif" height="1" width="7" ALT="">
                    </td>
                    <td width="150" align="left"><img src="/assets/images/headerbar_kerst.gif" alt="" ></td>

                </tr>
                <tr>
                    <td colspan="2" height="12"><img src="/assets/images/spacer.gif" alt="" height="12" width="1"></td>
                </tr>
            </table>
        </td>
        <td align="right" valign="top">&nbsp;
		<br/>
       <?php
    	    if ( isset($_SESSION['user']) ) {
	            $user = $_SESSION['user'];
	    ?>
                    <a href="/logout.php?redirect=/clubs/clubs.php"><img src="/assets/images/24x24/plain/exit.gif" border="0" alt="Log uit"></a>
					<br>&nbsp;<br>
					<span class="headerSmall">User <?=$_SESSION['user']->name?> logged in at <?=$user->login_date?>.</span>
	    <?php
	        }
	    ?>
        <td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td align="left">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td rowspan="2" width="7"><img src="../assets/images/spacer.gif" alt="" height="1" width="7"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
					<td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/newsbox.php" target="_top"><span class="tabName">Nieuwsbox</span></a></td>
					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
					<td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/tornooien/tornooien.html" target="_top"><span class="tabName">Tornooien</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/bestuur/bestuur.php" target="_top"><span class="tabName">Bestuur</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/advalvas/index.html" target="_top"><span class="tabName">Ad Valvas</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="http://www.frbe-kbsb.be/EloHist/FRBE_Fiche.php" target="_blank"><span class="tabName">ELO</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_FFFFFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="activeSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/clubs/clubs.php" target="_top"><span class="tabName">Clubs</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_FFFFFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/jeugd/index.html" target="_top"><span class="tabName">Jeugd</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>

					<td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_l.gif" height="14" width="14" ALT=""></td>
                    <td nowrap rowspan="2" class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt="" height="3" width="3"><br/><a href="/links/index.php" target="_top"><span class="tabName">Links</span></a></td>
                    <td valign="top"><img src="../assets/images/tabcorners/re_99CCFF_r.gif" height="14" width="14" ALT=""></td>
                    <td rowspan="2" width=2><img src="../assets/images/spacer.gif" alt="" height="1" width="2"></td>
				</tr>
				<tr>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="activeSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="activeSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
					<td class="inactiveSpacer"><img src="../assets/images/spacer.gif" alt=""></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td width="100%" bgcolor="#FFFFFF" colspan="13"><img border="0" width="30" src="../assets/images/FFFFFF.gif" height="12" alt=""></td>
	</tr>
</table>
<?php
    $success = false;
    if ( isset($_POST['name']) ) {
    	$user = $_SESSION['user'];
		$club_id = $_GET['club_id'];
		$name = $_POST['name'];
		$correspondent = $_POST['correspondent'];
		$correspondent_email = $_POST['correspondent_email'];
		$correspondent_function = $_POST['correspondent_function'];
		$website = $_POST['website'];
		$playdate_adults = $_POST['playdate_adults'];
		$playdate_youth = $_POST['playdate_youth'];
		$site = $_POST['site'];
		$site_address = $_POST['site_address'];
		$email_club = $_POST['email_club'];
		$comment = $_POST['comment'];

		if ( empty($name) ) {
        	echo "<center><strong style='color:#FFFFFF'>Niet alle velden zijn ingevuld.<strong><center>";
        } else if ($connect = mysql_connect(DB_SERVER, DB_USER, DB_PWD)) {
			mysql_select_db(DB_CATALOG);
        	$result = mysql_query("SET AUTOCOMMIT=0", $connect);
	        $result = mysql_query("BEGIN", $connect);

            $query = sprintf("UPDATE club SET clubname = '%s', correspondent = '%s', correspondent_email = '%s',
            	correspondent_function = '%s', website = '%s', playdate_adults = '%s', playdate_youth = '%s', site = '%s',
            	site_address = '%s', email_club = '%s', comment = '%s' WHERE club_id = %u", mysql_real_escape_string($name),
            	mysql_real_escape_string($correspondent), mysql_real_escape_string($correspondent_email),
            	mysql_real_escape_string($correspondent_function), mysql_real_escape_string($website),
            	mysql_real_escape_string($playdate_adults), mysql_real_escape_string($playdate_youth), mysql_real_escape_string($site),
            	mysql_real_escape_string($site_address), mysql_real_escape_string($email_club), mysql_real_escape_string($comment),
            	$club_id);

            if ($result = mysql_query($query, $connect)) {
            	$err = mysql_error();
				if (mysql_affected_rows($connect) == 1 || empty($err) ) {
                    $query = sprintf("INSERT INTO club_history (user_id, club_id) VALUES ('%d', '%d')", $user->user_id, $club_id);
                	if ($result = mysql_query($query, $connect)) {
                        $result = mysql_query("COMMIT", $connect);
                    	$success = true;
                    } else {
                    	$result = mysql_query("ROLLBACK", $connect);
                    	show_error("Clubhistoriek kon niet worden opgeslagen.".mysql_error());
                    }

                } else {
                	$result = mysql_query("ROLLBACK", $connect);
                	show_error("Clubgegevens konden niet worden gewijzigd (".mysql_error().")");
                }
            } else {
                show_error("Clubgegevens konden niet worden gewijzigd (".mysql_error().")");
            }
        }
    } else if ( isset($_GET['club_id']) ) {
		$club_id = $_GET['club_id'];
        $connect = mysql_connect(DB_SERVER, DB_USER, DB_PWD);
		mysql_select_db(DB_CATALOG);
        $query = sprintf("SELECT club_id, clubname, correspondent, correspondent_email, correspondent_function,
            	website, playdate_adults, playdate_youth, site, site_address, email_club, comment FROM club WHERE
            	club_id = '%u'", $club_id);
        $result = mysql_query($query, $connect);
		$row = mysql_fetch_assoc($result);
        $club_id = $row['club_id'];
		$name = $row['clubname'];
		$correspondent = $row['correspondent'];
		$correspondent_email = $row['correspondent_email'];
		$correspondent_function = $row['correspondent_function'];
		$website = $row['website'];
		$playdate_adults = $row['playdate_adults'];
		$playdate_youth = $row['playdate_youth'];
		$site = $row['site'];
		$site_address = $row['site_address'];
		$email_club = $row['email_club'];
		$comment = $row['comment'];
		mysql_free_result($result);
    }
?>
<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">
<tr>
		<td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">
				<tr><td>&nbsp;</td></tr>
			</table>
		</td>
		<td id="header" valign="top" width="100%">
			<table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
				<tr>
					<td bgcolor="#666666" width="70%">
						<span class="headerLarge">Clubs</span>
						<br>
						<span class="headerMedium">Bestuur, Info</span>
					</td>
					<td bgcolor="#666666" align="right" valign="top">&nbsp;

					</td>
				</tr>
			</table>
			<table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
				<tr>
					<td>&nbsp;</td>
					<td width="100%" height="20" colspan="2" class="quicklink">
						<a href="clubs.php" target="content">info</a> |
						<a href="clubs.php" target="content">bestuur</a>
					</td>
				</tr>
				<tr>
					<td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="../assets/images/spacer.gif" alt="" height="1" width="1"></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td valign="top">
						<table align="left" cellspacing="10" width="100%">
							<tr>
								<td>
								<span class="blackHeaderLarge">Wijzig clubgegevens '<?=$name?>'</span>
								<br>
							</tr>
							<tr>
								<td>
									<form action="" method="post">
                                    <table cellspacing="5" class="yellowBox">
                                    	<tr>
                                    		<td width="30%"><strong>Nummer</strong></td>
                                    		<td><strong><?= $club_id ?></strong></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Naam</strong></td>
                                    		<td><input name="name" type="text" size="40" value="<?= $name ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Correspondent</strong></td>
                                    		<td><input name="correspondent" type="text" size="30" value="<?= $correspondent ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>E-mail correspondent</strong></td>
                                    		<td><input name="correspondent_email" type="text" size="40" value="<?= $correspondent_email ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Functie correspondent</strong></td>
                                    		<td><input name="correspondent_function" type="text" size="30" value="<?= $correspondent_function ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Website</strong></td>
                                    		<td><input name="website" type="text" size="40" value="<?= $website ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Speeldatum volwassenen</strong></td>
                                    		<td><input name="playdate_adults" type="text" size="20" value="<?= $playdate_adults ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Speeldatum jeugd</strong></td>
                                    		<td><input name="playdate_youth" type="text" size="20" value="<?= $playdate_youth ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Lokaal</strong></td>
                                    		<td><input name="site" type="text" size="35" value="<?= $site ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Adres</strong></td>
                                    		<td><input name="site_address" type="text" size="50" value="<?= $site_address ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>E-mail</strong></td>
                                    		<td><input name="email_club" type="text" size="40" value="<?= $email_club ?>"/></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Commentaar</strong></td>
                                    		<td><textarea name="comment" cols="80" rows="3"><?= $comment ?></textarea></td>
                                    	</tr>
                                        <tr>
											<td colspan="2"><input type="submit" value="Wijzig clubgevens" class="submit"/></td>
										</tr>
	                                </table>
	                                </form>
								</td>
							</tr>
                            <tr>
								<td><a href="clubs.php"><img border="0" src="../../assets/images/24x24/shadow/home.gif">
								<strong style="font-size:11px">Toon clubs</strong></a></td>
							</tr>
							<?php
                            	if ($success) {
                            ?>
                            <tr>
								<td><strong style="background-color:#FFFFCC">Clubgegevens zijn gewijzigd (<a href="club_detail.php?club_id=<?=$club_id?>">detail</a>).</strong></td>
							</tr>
                            <?php
                                }
							?>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>
